home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / qq_norma < prev    next >
Text File  |  1995-11-20  |  2KB  |  70 lines

  1. //  QQ_NORMAL
  2. //  Input: e = unsorted error residual vector to be checked.
  3. //  Output: eq = sample quantile (sorted e)
  4. //          nq = theoretical N(0,1) quantile.
  5. //  Plot (nq,eq) as (x,y) pairs to make a Q-Q plot.
  6. //  
  7. //    ^ Usage: ^
  8. //  [nq,eq]=QQ_NORMAL(e);
  9. //  plot(nq,eq,'o')
  10. //  xlabel('Theoretical Normal N(0,1) Quantile')
  11. //  ylabel('Sorted data values (user units)')
  12.  
  13. //   ^ Uses Matlab function "inverf", inverse error fn. ^
  14. //   Tests the elements of vector e to examine whether they
  15. //   are distributed according to a normal distribution.  The
  16. //   output of this function may be used to construct a q-q
  17. //   plot, for visual inspection of the distribution. If a normal
  18. //   distribution is appropriate, the resulting locus of (nq,eq)
  19. //   pairs will approximately follow a straight line, whose
  20. //   intercept and slope respectively correspond to the mean
  21. //   and standard deviation of the normal distribution.
  22. //   Outliers, if present, appear as departures from linearity,
  23. //   usually away from the origin, and are easily identified.
  24. //   Keywords: Outliers, Robust Statistics, Data analysis
  25.  
  26. //   Copyright (c) 1989 by Peter R. Shaw
  27. //   Permission to copy all or part of this work is granted, provided
  28. //   that the copies are not distributed for resale, and that the
  29. //   copyright notice and this notice are retained.
  30. //  
  31. //   If you make any improvements, please let me know.
  32.  
  33. //   Peter R. Shaw
  34. //   Woods Hole Oceanographic Institution
  35. //   Woods Hole, MA 02543
  36. //   (508) 457-2000 ext. 2473
  37. //   pshaw@aqua.whoi.edu
  38.  
  39. //   Translated to RLaB 5/10/93, Ian Searle
  40.  
  41. //   Reference:
  42. //   Lewis, T. and N. I. Fisher, Graphical methods for investigating
  43. //   the fit of a Fisher distribution to spherical data; Geophys. J.
  44. //   R. Astr. Soc., 69:1-13, 1987.
  45.  
  46. require erf
  47.  
  48. qq_normal = function ( e )
  49. {
  50.   local (eq, ivec, n, n2, nq, neg, pos);
  51.  
  52.   n = e.nr; 
  53.   n2 = e.nc;
  54.  
  55.   if (n2 > 1) { error("(qq_normal): e must be a vector."); }
  56.  
  57.   n = length (e);
  58.   eq = sort(e).val;
  59.   ivec = ((1:n)'-.5)./n;
  60.   pos = (ivec >= .5);
  61.   neg = !pos;
  62.   nq = zeros (size (e));
  63.   nq[find (neg)] = -sqrt (2)*inverf (2*(.5-ivec[find (neg)]));
  64.   nq[find (pos)] = +sqrt (2)*inverf (2*(ivec[find (pos)]-.5));
  65.  
  66.   return [nq, eq];
  67. }
  68.  
  69.  
  70.